package wizard;

import components.Button;
import components.CheckBox;
import components.ComboBox;
import components.Dic;
import components.Dic2;
import components.Frame;
import components.Label;
import components.LinkText;
import components.PostCode;
import components.TextBox;
import components.UrlLink;
import components.UserLogin;
import componentsAbstract.CompAbstract;

public class ComponentResolver {
	
	
	public static boolean resolve(CompAbstract comp) throws Exception
	{
		
		if(comp instanceof Frame) {
			Frame fr = (Frame)comp;
			fr.switchTo();
		} 
		
		else if(comp instanceof TextBox)
		{
			TextBox tb = (TextBox)comp;
			tb.findObject();
			tb.safeSendKeys();
			
		}  
		
		else if(comp instanceof Button) {
			Button bt = (Button)comp;
			bt.findObject();
			bt.click();
			
		}  
		
		else if(comp instanceof ComboBox) {
			ComboBox cb = (ComboBox)comp;
			cb.findObject();
			if(cb.isChoiceByIndex()) {
				cb.selectByIndex();
			} else if (cb.isChoiceByText()){
				cb.selectByText();
			}
		} 
		
		else if(comp instanceof Dic) {
			Dic dic = (Dic)comp;
			dic.findObject();
			dic.openDic();
			dic.search();
			dic.chooseFromDic();
			
		}
		
		else if(comp instanceof PostCode) {
			PostCode pc = (PostCode)comp;
			pc.findObject();
			pc.sendKeys();				
			
		}
		
		else if(comp instanceof CheckBox) {
			CheckBox cb = (CheckBox)comp;
			cb.findObject();
			cb.click();
			
		}  
		
		else if(comp instanceof UserLogin) {
			UserLogin ul = (UserLogin)comp;
			ul.logIn();
			
		}  
		
		else if(comp instanceof LinkText) {
			LinkText lt = (LinkText)comp;
			lt.findObject();
			lt.safeClick();
			
		}  
		else if(comp instanceof UrlLink) {
			UrlLink ul = (UrlLink)comp;
			ul.navigate();				
		}  
		else if(comp instanceof Label) {
			Label la = (Label)comp;
			if(!la.safeFindLabel())
			{
				throw new Exception("Nie znaleziono tekstu na stronie: "+ la.toString());
			}
				
		}  
		else if(comp instanceof Dic2) {
			Dic2 dic = (Dic2)comp;
			dic.findObject();
			dic.openDic();
			dic.chooseFromDic();	
		} else
		{
			return false;
		}
		
		return true;
		
		
	}

	
}
